function W = DeltaMiniBatch(W, X, D)
    alpha = 0.9;
    batchSize = round(0.5 * size(X, 1)); % 计算批次大小
    numBatches = ceil(size(X, 1) / batchSize); % 总共需要处理的批次数
    
    for batch = 1:numBatches
        dWsum = zeros(3, 1);
        
        % 确定当前批次的起始和结束索引
        startIdx = (batch - 1) * batchSize + 1;
        endIdx = min(batch * batchSize, size(X, 1));
        
        for k = startIdx:endIdx
            x = X(k, :)';
            d = D(k);

            v = W*x;
            y = Sigmoid(v);

            e = d - y;    
            delta = y*(1-y)*e;

            dW = alpha*delta*x;

            dWsum = dWsum + dW;
        end
        
        dWavg = dWsum / (endIdx - startIdx + 1);
        
        W(1) = W(1) + dWavg(1);
        W(2) = W(2) + dWavg(2);
        W(3) = W(3) + dWavg(3);
    end
end

function y = Sigmoid(v)
    y = 1 ./ (1 + exp(-v));
end